package com.hust360.percent.pojo;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.hust360.percent.PercentApplication;

public class DiscountLocal extends Discount implements Serializable {


	/**
	 * 
	 */
	private static final long serialVersionUID = -4579955174983463414L;

	public DiscountLocal() {
	}

	@Override
	public List<Image> getImages() {
		return PercentApplication.imageDAO.findByDscId(id);
	}

	@Override
	public Shop getShop() {
		Shop shop = null;
		synchronized (PercentApplication.shopDao) {
			shop = PercentApplication.shopDao.findById(shopid);
		}
		return shop;
	}

	@Override
	public List<Appraise> getAppraises() {
		Map<String, String> map = new HashMap<String, String>();
		map.put(Appraise.DSCID, id + "");
		return PercentApplication.appraiseDAO.findWithMap(map);
	}

	@Override
	public float getRate() {
		List<Appraise> list = getAppraises();

		if (list == null || list.size() == 0) {
			return 0;
		}

		double total = 0;
		for (Appraise app : list) {
			total += app.rate;
		}
		return (float) total / list.size();
	}

}
